package com.duqc.quartz;

import com.duqc.response.ResultMsg;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SchedulerJobController
 * @Description SchedulerJobController
 * @Author duqc
 * @Date 2021/9/7
 **/
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/job")
public class SchedulerJobController {

    private final JobUtil jobUtil;

    @PostMapping("/save")
    public ResultMsg<Object> jobSave(@RequestBody ScheduleJob scheduleJob) {
        this.jobUtil.saveTask(scheduleJob);
        return ResultMsg.success();
    }

    @GetMapping("/remove")
    public ResultMsg<Object> jobRemove(String jobName, String jobGroup) {
        this.jobUtil.remove(jobName, jobGroup);
        return ResultMsg.success();
    }

    @GetMapping("/state")
    public ResultMsg<Object> jobState(String jobName, String jobGroup) {
        return ResultMsg.success(this.jobUtil.getJobState(jobName, jobGroup));
    }

    @GetMapping("/pause")
    public ResultMsg<Object> jobPause(String jobName, String jobGroup) {
        this.jobUtil.pauseJob(jobName, jobGroup);
        return ResultMsg.success();
    }

    @GetMapping("/resume")
    public ResultMsg<Object> jobResume(String jobName, String jobGroup) {
        this.jobUtil.resumeJob(jobName, jobGroup);
        return ResultMsg.success();
    }
}
